package com.javatwo;

import java.util.*;

public class Demo6 {
    public static void main(String[] args) {
        User user= new User();
        user.id=001;
        user.name="张三";
        user.password="123";

        //购物车
        List<Menu> menusOrder = new ArrayList<Menu>();

        Map<String,Object> map = new HashMap<String,Object>();
        map.put("1",menusOrder);



        String string = menusOrder.toString();
        //菜单的容器
        List<Menu> menus = new ArrayList<Menu>();
        List<Integer> num = new ArrayList<Integer>();
        num.add(2);
        num.add(1);

        for (int i:num) {
            System.out.println(i);
        }


        Menu menu = new Menu();
        menu.id=1;
        menu.mName="红烧肉";
        menu.mPrice=28.5;
        Menu menu1 = new Menu();
        menu1.id=2;
        menu1.mName="炒青菜";
        menu1.mPrice=8;
        Menu menu2 = new Menu();
        menu2.id=3;
        menu2.mName="西红柿炒鸡蛋";
        menu2.mPrice=9;
        Menu menu3 = new Menu();
        menu3.id=4;
        menu3.mName="佛跳墙";
        menu3.mPrice=999;

        menus.add(menu);
        menus.add(menu1);
        menus.add(menu2);
        menus.add(menu3);

        Scanner scanner = new Scanner(System.in);
        System.out.println("-----欢迎进入Kh62点餐系统----");
        System.out.println("选择您的操作：");
        System.out.print("1：登录");
        System.out.println("2：注册");
        int i = scanner.nextInt();
        switch (i){
            case 1:
                //登录
                System.out.println("请输入账号名：");
                String name = scanner.next();
                System.out.println("请输入密码：");
                String password = scanner.next();
                //怎么存人：名称，密码，编号 --->容器(自定义)
                if(name.equals(user.name) &&password.equals(user.password)){
                    System.out.println("请选择你需要的操作：");
                    System.out.println("1：查看菜单");
                    System.out.println("2：查看订单");
                    System.out.println("3：退款");
                    System.out.println("4：评价");
                    System.out.println("5：退出");
                    int i1 = scanner.nextInt();
                    switch (i){
                        case 1:
                            //todo 查看菜单
                            System.out.println("编号\t\t\t名称\t\t\t\t\t单价");
                            for (int j=0;j<menus.size();j++){
                                System.out.println(menus.get(j).id+"\t\t\t"+menus.get(j).mName+"\t\t\t"+menus.get(j).mPrice);
                            }
                            System.out.println("请选择您需要点餐的编号");
                            int i2 = scanner.nextInt();
                            //根据菜品Id进行查询
                            for (int j=0;j<menus.size();j++){
                                if(menus.get(j)!=null && menus.get(j).id==i2){
                                    for (int k=0;k<menusOrder.size();k++){
                                            if(menusOrder.get(k)==null){
                                                menus.get(j).count++;
                                                menusOrder.add(menus.get(j));
                                                break;
                                            }
                                    }
                                }
                            }
                            System.out.println("点餐成功，是否需要继续点餐(y/n)");
                            String next = scanner.next();
                            boolean isFlag=false;
                            if(next.equals("y")){
                                isFlag=true;
                            }
                            while (isFlag){
                                System.out.println("请选择您需要点餐的编号");
                                int i3 = scanner.nextInt();
                                //根据菜品Id进行查询
                                for (int j=0;j<menus.size();j++){
                                    if(menus.get(j)!=null && menus.get(j).id==i3){
                                        for (int k=0;k<menusOrder.size();k++){
                                            if(menusOrder.get(k)!=null && menusOrder.get(k).id==i3){
                                                menusOrder.get(k).count++;
                                                break;
                                            }else {
                                                for (int r=0;r<menusOrder.size();r++){
                                                    if(menusOrder.get(k)==null){
                                                        menus.get(j).count++;
                                                        menusOrder.add(menus.get(j));
                                                        break;
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                                System.out.println("点餐成功，是否需要继续点餐(y/n)");
                                String next1= scanner.next();
                                if(next1.equals("y")){
                                    isFlag=true;
                                }else {
                                    isFlag=false;
                                }
                            }

                            System.out.println("编号\t\t\t名称\t\t\t价格\t\t\t数量");
                            for (int o=0;o<menusOrder.size();o++){
                                if(menusOrder.get(o) !=null){
                                    System.out.println(menusOrder.get(o).id+"\t\t\t"+menusOrder.get(o).mName+"\t\t\t"+menusOrder.get(o).mPrice+"\t\t\t"+menusOrder.get(o).count);
                                }
                            }

                            break;
                        case 2:
                            //todo 查看订单
                            break;
                        case 3:
                            //todo 退款
                            break;
                        case 4:
                            //todo 评价
                            break;
                        case 5:
                            //todo 退出
                            break;
                    }

                }

                break;
            case 2:
                //注册
                break;
            default:
                System.exit(1);
        }
    }
}
